my $infilelinear = "linear/$ARGV[0].linear";	# to get equations.
my $infilegen = "../gen/$ARGV[0].gen";		# to get no of vars.

sub getallvars {
	my ($nvars) = @_;
	$allvars = "";
	my $ii = 0;
	for (; $ii < $nvars - 1; ++$ii) {	# last entry after loop.
		$allvars .= "v$ii, ";
	}
	$allvars .= "v$ii";
	return $allvars;
}

open(FD, $infilelinear);
my @all = <FD>;
close(FD);

open(FDGEN, $infilegen);
my @allgen = <FDGEN>;
close(FDGEN);

chomp($allgen[0]);
my $nvars = $allgen[0];
my $allvars = getallvars($nvars);

my $outfile = "maxima/$ARGV[0].maxima";
open (FD, ">$outfile");

print FD "eqns: [\n";
my $nall = scalar @all;
my $ii = 0;
for (; $ii < $nall - 1; ++$ii) {	# last entry after loop.
	chomp($all[$ii]);
	print FD $all[$ii].",\n";
}
print FD $all[$ii];			# last entry without ending comma.
print FD "];\n";
print FD "solve(eqns, [$allvars]);\n";

close(FD);

